#include "GameManager.h"
#include "GameState.h"


GameManager::GameManager()
{
}

GameManager::~GameManager()
{
}

void GameManager::start(GameState* state)
{
	changeState(state);
}


void GameManager::changeState(GameState* state)
{
	// cleanup the current state
	if ( !mStates.empty() ) {
		mStates.back()->exit();
		mStates.pop_back();
	}

	// store and init the new state
	mStates.push_back(state);
	mStates.back()->enter();
}

void GameManager::pushState(GameState* state)
{
	// pause current state
	if ( !mStates.empty() ) {
		mStates.back()->pause();
	}

	// store and init the new state
	mStates.push_back(state);
	mStates.back()->enter();
}

void GameManager::popState()
{
	// cleanup the current state
	if ( !mStates.empty() ) {
		mStates.back()->exit();
		mStates.pop_back();
	}

	// resume previous state
	if ( !mStates.empty() ) {
		mStates.back()->resume();
	}
}


void GameManager::frameStarted(float dt)
{
	mStates.back()->frameStarted(dt);
}


void GameManager::frameEnded(float dt)
{
	// call frameEnded of current state
	mStates.back()->frameEnded(dt);
}

bool GameManager::keyPressed( const OIS::KeyEvent &e )
{
    // Call keyPressed of current state
    mStates.back()->keyPressed( e );

    return true;
}


bool GameManager::keyReleased( const OIS::KeyEvent &e )
{
    // Call keyReleased of current state
    mStates.back()->keyReleased( e );

    return true;
}

bool GameManager::mouseMoved( const OIS::MouseEvent &e )
{
    // Call mouseMoved of current state
    mStates.back()->mouseMoved( e );

    return true;
}


bool GameManager::mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id )
{
    // Call mousePressed of current state
    mStates.back()->mousePressed( e, id );

    return true;
}

bool GameManager::mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id )
{
    // Call mouseReleased of current state
    mStates.back()->mouseReleased( e, id );

    return true;
}
